﻿package view.task
{
    import com.core.*;
    import com.sh.game.util.*;
    import flash.events.*;
    import manager.*;
    import morn.core.components.*;
    import plugin.instance.*;
    import view.message.*;

    public class TDItem extends Component
    {
        private var _txt1:Label;
        private var _txtName:Label;
        private var mapid:int = 10318;
        private var hascount:int = 0;

        public function TDItem()
        {
            var _loc_1:Boolean = true;
            mouseEnabled = true;
            mouseChildren = _loc_1;
            this._txt1 = new Label(MColor.getHMTL("[经验]", 6) + "<u>守护皇城</u>");
            this._txt1.isHtml = true;
            this._txt1.color = MColor.New16;
            this._txt1.align = "left";
            this._txt1.stroke = "0x0";
            this._txt1.addEventListener(MouseEvent.CLICK, this.linkHandler);
            this.addChild(this._txt1);
            this.updateCount();
            return;
        }// end function

        private function linkHandler(event:MouseEvent) : void
        {
            var e:* = event;
            if (this.hascount > 0)
            {
                Alert2.show("即将传送，是否确认前往！", "温馨提示", ["确定", "取消"], function (param1:int, param2:Object) : void
            {
                if (param1 == 0)
                {
                    PluginManager.instance.sendToServer("instance", CMDInstance.NpcInstance, {mapid:mapid, type:0});
                }
                return;
            }// end function
            );
            }
            else
            {
                ModelProxy.change("mainuiInstance", "enterInstance", this.mapid);
            }
            return;
        }// end function

        public function updateCount() : void
        {
            var _loc_1:* = ModelProxy.getValue("data", "dayinstances");
            var _loc_2:* = ConfigDictionary.data.instance;
            var _loc_3:* = _loc_2[this.mapid];
            var _loc_4:* = String(_loc_3.limit_times).split(" ");
            var _loc_5:int = 0;
            if (_loc_1 == null || !_loc_1.hasOwnProperty(this.mapid))
            {
                _loc_5 = _loc_5 + int(_loc_4[1]);
            }
            else if (int(_loc_1[this.mapid]) < int(_loc_4[1]))
            {
                _loc_5 = _loc_5 + (int(_loc_4[1]) - int(_loc_1[this.mapid]));
            }
            this.hascount = _loc_5;
            if (_loc_5 > 0)
            {
                this._txt1.text = MColor.getHMTL("[经验]", 6) + "<u>守护皇城</u>";
            }
            else
            {
                this._txt1.text = MColor.getHMTL("[经验]", 6) + MColor.getHMTL("<u>守护皇城</u>", 9);
            }
            return;
        }// end function

    }
}
